package model

import (
	"gorm.io/gorm"
	"types"
)

// 课程表
type Class struct {
	gorm.Model
	UserId    int     `gorm:"type:int(11);index;not null;comment:用户id"`
	SeaId     int     `gorm:"type:int(11);not null;comment:评论表"`
	Name      string  `gorm:"type:varchar(30);not null;comment:课程名称"`
	ClassTime string  `gorm:"type:varchar(53);not null;comment:课程时长"`
	Price     float64 `gorm:"type:decimal(10,2);not null;comment:课程价格"`
	New       int     `gorm:"type:int(11);not null;comment:现在人数"`
	Max       int     `gorm:"type:int(11);not null;comment:容量"`
}

// 课表添加
func (c *Class) ClassAdd() error {
	return types.Db.Create(&c).Error
}

// 课程列表
func (c *Class) ClasList() (class *[]Class, err error) {
	types.Db.Find(&class)
	return
}

// 课程名额更新
func (c *Class) ClassUpdate() (class *Class, err error) {
	types.Db.Where("name=?", c.Name).Update("new", class.New)
	return
}

// 统计
func (c *Class) ClassCounter() (class *Class, err error) {

	return
}
